<template>
    <div>
        <van-nav-bar
                title="登录"
                left-arrow
                @click-left="$router.push({path: '/'})"
                style="background-color:#f2f2f2;"
        />
        <div style="background-color: #fff;padding:15px 0 15px 0;border-radius:10px;margin: 10px;height: 450px">
            <div class="logo">
                <img :src="avatar" style="border-radius: 35px;width:70px;height:70px;margin-bottom:10px" >

                <div v-if="nickName !== ''">
                    <p style="margin-top: 20px">{{ nickName }}</p>
                    <p style="margin-top: 10px">欢迎回来</p>
                </div>

            </div>
            <div style="padding: 100px 20px">
                <van-button color="#58aa49" size="large" @click="wechatlogin" style="border-radius: 50px">微信一键登陆
                </van-button>

                <van-button color="#7488c3" size="large" style="margin-top: 30px;border-radius: 50px"
                            @click="$router.push({ name: 'loginbyphone'})">手机号验证登陆
                </van-button>
            </div>
        </div>
    </div>
</template>

<script>
    import {authLogout, authReset} from "@/api/api";
    import {justWx} from "@/api/api";
    import {getLocalStorage} from '@/utils/local-storage';


    export default {
        name: "login-new",
        data() {
            return {
                avatar: require('./user-avatar.jpg'),
                nickName: ''
            }
        },
        created() {
            const nickName = getLocalStorage('nickName').nickName
            const avatar = getLocalStorage('avatar').avatar

            if( avatar !== null){
                this.avatar = getLocalStorage('avatar').avatar
            }
            if ( nickName !== null){
                this.nickName = getLocalStorage('nickName').nickName
            }

            console.log(this.nickName)
            console.log(this.avatar)

        },
        methods: {
            wechatlogin() {
                // justWx({
                //     // code:this.code
                // }).then( res => {
                //     console.log(res)
                //
                // }).catch( error => {
                //     console.log(error)
                // })

                location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5b93f2b90f92962d&redirect_uri=' +
                    encodeURIComponent('http://www.moteer.top/#/loginbywx') + '&response_type=code&scope=snsapi_userinfo#wechat_redirect'
            },
        }
    }
</script>

<style scoped>
    .logo {
        width: 100%;
        text-align: center;
        margin-top: 20px;
    }

    .logo img {
        width: 50%;
    }
    .logo p{
        margin-top: 20px;
    }
</style>
